<?php
namespace app\admin\controller;

use think\Controller;
use app\admin\model\Admin as AdminModel;
class Admin extends Controller
{
    public function lst()
    {
        $list = AdminModel::paginate(2);
        $this->assign('list',$list);
        return $this->fetch();
    }

    public function add()
    {
        if (request()->isPost()) {

            $validate = new \think\Validate([
                'username' => 'require|max:25',
                'password' => 'require|max:25',
            ]);

            $data = [
                'username' => input('username'),
                'password' => md5(input('password')),
            ];
            $validate = \think\Loader::validate('Admin');
            if (!$validate->scene('add')->check($data)) {
                return $this->error($validate->getError());
                die();
            }

            if (db('admin')->insert($data)) {
                return $this->success('添加管理员成功!', 'lst');
            } else {
                return $this->error('添加管理员失败!');
            }
            return;
        }

        return $this->fetch();
    }

    public function del(){
        echo input('id');
    }
}
